<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<body>

<form id="form_member_update" class="form-horizontal" autocomplete="off">

    <input type="hidden" name="keyId" id="keyId" th:value="${user?.id}"/>

    <div class="form-group">
        <label class="col-md-2 control-label">用户名称<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-8">
            <input type="text" name="name" id="name" class="form-control" placeholder="" th:value="${user?.name}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-2 control-label">用户名<i class="fa fa-asterisk txt-color-red"></i></label>
        <div class="col-md-8">
            <input type="text" name="username" id="username" class="form-control" placeholder="" th:value="${user?.username}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-2 control-label">手机号</label>
        <div class="col-md-8">
            <input type="text" name="phone" id="phone" class="form-control" placeholder="" th:value="${user?.phone}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-2 control-label">邮箱</label>
        <div class="col-md-8">
            <input type="text" name="email" id="email" class="form-control" placeholder="" th:value="${user?.email}">
        </div>
    </div>

</form>

</body>

<script th:inline="javascript">
    $(function(){

        fn_member_update_validate();

    });


    // 表单数据校验
    function fn_member_update_validate() {
        __init_validate('form_member_update', {
            rules : {
                name : {
                    required : true
                },
                username : {
                    remote : {
                        type: 'post',
                        url: '/main/member/validate/account',
                        data: {
                            account: function() {
                                return $('#form_member_update #username').val()
                            },
                            keyId : function(){
                                return $('#form_member_update #keyId').val();
                            }
                        }
                    }
                },
                phone : {
                    checkPhone : true,
                    remote : {
                        type: 'post',
                        url: '/main/member/validate/account',
                        data: {
                            account: function() {
                                return $('#form_member_update #phone').val()
                            },
                            keyId : function(){
                                return $('#form_member_update #keyId').val();
                            }
                        }
                    }
                },
                email : {
                    email : true,
                    remote : {
                        type: 'post',
                        url: '/main/member/validate/account',
                        data: {
                            account: function() {
                                return $('#form_member_update #email').val()
                            },
                            keyId : function(){
                                return $('#form_member_update #keyId').val();
                            }
                        }
                    }
                },
            },
            messages : {
                phone : {
                    remote : "已经存在又此手机号了"
                }
            }
        });
    }

    $.validator.addMethod("checkPhone", function(value, element, params){
        var checkPhone = /^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/;
        return this.optional(element) || (checkPhone.test(value));
    },"请输入正确的手机号");

    function fn_member_update_save(callback) {
        if (!$('#form_member_update').valid()) {
            return false;
        }
        __confirm_dialog('提示', "确定提交么?",
            function () {
                __form_save('form_member_update', '/main/member/update', function(data) {
                    callback(data);
                });
            },
            function () {
                callback();
            }
        );
    }
</script>

</html>